<?php
/**
 * @package model.dao
 * @author Mufeed
 * @copyright Copyright &copy; 2011, synergyquad
 * @since 1.0 - May-18-2011
 * @version 1.1
 */

require_once 'vo/UserVO.php';
require_once 'vo/AdminVO.php';
require_once 'vo/ForumVO.php';
require_once 'vo/CompanyVO.php';
require_once 'vo/AttachmentVO.php';
require_once 'vo/NotificationVO.php';


class MakeDAOImpl
{
	
	/**
	 * @access public
	 * @staticvar Instance of MemberDAOImpl
	 */
	public static $_instance	= null;
	
	
	/**
	 * <p>Get an instance of MakeDAOImpl</p>
	 * 
	 * @access public
	 * @return MakeDAOImpl Instance of MakeDAOImpl
	 */
	public static function getInstance() 
	{
		if(self::$_instance == null) 
		{
			self::$_instance = new MakeDAOImpl();
		}
		
		return self::$_instance;
	}
	
	/**
	* Get make details restricted by count and search key 
	*/
	public function getAllMakes($start, $count, $searchKey) 
	{
		$arrayCollection = null;
		$where='';
		$arrayCollection = null;
		$query_data = "SELECT * FROM vehicle_make WHERE (deleted=0 AND active=1) ";
		 //SELECT * FROM vehicle_make WHERE (deleted=1 AND active=1) AND (make LIKE '%acura%' OR created_by LIKE '%2%')\\(deleted=0 AND active=1) AND (
		if($searchKey)
			$where= "AND (make LIKE '%".$searchKey."%' OR updated_by LIKE '%".$searchKey."%' OR created_by LIKE '%".$searchKey."%') ";
		$query_data.=$where."LIMIT ".$start.",".$count;
		
		$query_count = "SELECT COUNT(*) as count FROM vehicle_make WHERE (deleted=0 AND active=1)  ".$where;
		$result_count = mysql_fetch_array(mysql_query($query_count));
		
		$result_data = mysql_query($query_data) or die($query_data);
		$result_array = array();
		while($row =  mysql_fetch_object($result_data))
		{
			array_push($result_array, $row);
		}
		
		$arrayCollection = new ArrayCollection();
		$arrayCollection->makes = $result_array;
		$arrayCollection->count = $result_count["count"];
		
		return $arrayCollection;
	}
	
	/**
	* Get all the make ids and make name 
	*/
	public function getMakes()
	{
		$query_data = "SELECT make_id,make FROM vehicle_make WHERE deleted=0 AND active=1";
		$result_data = mysql_query($query_data) or die($query_data);
	
		$result_array = array();
		while($row =  mysql_fetch_object($result_data))
		{
			array_push($result_array, $row);
		}
		
		return $result_array;
	}
	/**
	*Delte make by id
	*/
	public function deleteMake($makeID)
	{
		$query_data = "UPDATE vehicle_make SET deleted=1 WHERE make_id='".$makeID."'";
		$result = mysql_query($query_data) or die($query_data);
		
		$query_data = "UPDATE vehicle_model SET deleted=1 WHERE make_id='".$makeID."'";
		$result = mysql_query($query_data) or die($query_data);
		
		return $result;
	}
	
	/**
	*Add a new make
	*
	*/
	public function addMake($makeVO)
	{
	
		$queryString = "INSERT INTO vehicle_make(`make_id`,`make`, `description`,`created_by`, `create_date`) VALUES(NULL,'".$makeVO->make."','".$makeVO->description."','".$makeVO->createdBy."',now() )";
	
		$result = mysql_query($queryString) or die($queryString);
		return $result;
	}
	
	/**
	*Edit Make
	*/
	public function editMake($makeVO)
	{
	
		$queryString = "UPDATE vehicle_make SET make='" .$makeVO->make. "', description='" .$makeVO->description. "', updated_by='" .$makeVO->editedBy. "', update_date=now() WHERE make_id=".$makeVO->makeID;
		$result = mysql_query($queryString) or die($queryString);
		return $result;
		
	}
	
} 
?>